﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_SMS_GetNewMsgCount_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_SMS_GetNewMsgCount_V2];
GO
CREATE PROCEDURE [dbo].[sproc_SMS_GetNewMsgCount_V2]
    @username nvarchar(50)
/*

===================================================
功能:    得到某用户最新消息数
参数:
    @username         ;    用户名
===================================================

*/
AS
BEGIN
SET NOCOUNT ON;

SELECT COUNT(1) 
    FROM 
        dbo.UDS_SMS_Msg M INNER JOIN dbo.UDS_SMS_Receiver R ON M.ID = R.MsgID
    WHERE
        R.Receiver = @Username 
        and R.IsRead = 0 
        and M.Type = /* site message */ 1;

END
GO
